import React from 'react'
// ===================================================================== Temp
import TableModal from '#cpt/temp/TableModal'
// ===================================================================== Declare
const { $http, $fn, $Lazy } = window
// ===================================================================== Lazy
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		selectedKeys:[],
		selectedRows:[],
		pag: {},
		forms: [
			{ label: '标本类型',		name: 'item_code',	type: 'select', loading:true, idStr:'code' },
		]
	}
	
	model = {}
	
	open = (kind_id) => {
		this.modal.open()
		const { keys } = this.props
		this.setState({ selectedKeys: keys })
		this.kind_id =  kind_id
		this.fetch()
		this.getSelect()
	}
	
	// paging
	fetch = () => {
		console.log(this)
		$http.submit(this,'dis-item/item', {param:{dis_code: 2000, item_code: this.model?.item_code }, loadingText:'数据加载中'}).then((data)=>{
			this.setState({data})
		})
	}
	
	// 获取下拉框数据
	getSelect = async () => {
		const { forms } = this.state
		$cache.then( async f => {
			//标本类型
			$fn.setRow(forms, 'item_code', await f.getDicCache({ code: 2000 }) )
			//
			this.setState({ forms })
		})
	}
	
	// 表单
	cols = [
		{ title: 'id', 			dataIndex: 'value', 	 },
		{ title: '标本类型', 	dataIndex: 'name', 		 },
	]
	
	render(){
		const { type, onRefresh } = this.props
		return TableModal.call(this,{ title: type? '禁用标本类型' : '允许标本类型', labelWidth:'s7', width:'30%', height:'80%', isIndex:true, idStr: 'value',
			onOk:()=> {
				let param
				if (type) {
					param = {dis_spec_model: this.state.selectedRows, kind_id: this.kind_id}
				} else {
					param = {en_spec_model: this.state.selectedRows, kind_id: this.kind_id}
				}
				$http.submit(this,'collection/addenspec', {param, loadingText:'数据加载中'}).then((data)=>{
					this.modal.close()
					onRefresh()
				})
			}
		})
	}
}

export default Index